package com.warmlight.voicepacket.view.picture;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

/**
 * Created by weiweijinpeng on 2018/9/10.
 */

public class PlayskinScrollGirdView extends GridView {


    public PlayskinScrollGirdView(Context context) {
        super(context);
    }

    public PlayskinScrollGirdView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int  expandSpec = 0;
        try {
            int size = getAdapter().getCount();

            if (size == 1) {
                setNumColumns(1);
            }else if ( size==2 || size == 4  ) {
                setNumColumns(2);
            } else {
                setNumColumns(3);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec,expandSpec );
    }
}
